package com.dailyblue.javaee.servlet;

import jakarta.servlet.http.*;

import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Arrays;

// 注册servlet
@WebServlet(value = "/third",loadOnStartup = 1)
public class ThirdServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("我是ThirdServlet类的服务方法");
        request.setAttribute("A", "request内容");
        // 获取到session对象
        HttpSession session = request.getSession();
        session.setAttribute("B", Arrays.asList("aa", "bb", "cc"));
        // 获取到application对象
        ServletContext application = session.getServletContext();
        application.setAttribute("C", 19876);
        request.getRequestDispatcher("2.jsp").forward(request, response);
    }
}